var vm =  new Vue({
      el : "#app",
      data : {
      	order_type:null,//点击的订单选项状态
      	hisOrder:[],//订单总集合
        userId:'',//缓存客户id
      	page:1,//默认第几页
      	tipMsg:'加载中',//加载提示文字
        token:''//固定验证id
      },
  created:function(){
	this.token = _lSGet('token');
	this.userId = _lSGet('userId');
	this.get_data();

  },
  mounted:function(){
	var that=this;
	$(window).scroll(function(){//判断页面到底
　　var scrollTop = $(this).scrollTop();
　　var scrollHeight = $(document).height();
　　var windowHeight = $(this).height();
　　if(scrollTop + windowHeight == scrollHeight){
　　　　//alert("you are in the bottom");
		that.page++;
		that.get_data();
		//alert(that.page);
		//console.log(that.page);
		//console.log(that.hisOrder);
	  	layer.open({
		type: 2
		,content: that.tipMsg
		,time: 0.5
		});
　　　　}
    });

  },
 methods:{
   sendRequest:function(urls,params,successFunc){//封装请求方法
      $.ajax({
        type: "post",
        url:url+urls,
        data:params,
        cache:false,
        //contentType:'application/x-www-form-urlencoded',
        async:true,
        //dataType: 'json',
        success: successFunc
    		});
    },
   fmtDate:function (obj){//封装时间戳转时间方法
        var date =  new Date(obj);
        var y = 1900+date.getYear();
        var m = "0"+(date.getMonth()+1);
        var d = "0"+date.getDate();
        return y+"-"+m.substring(m.length-2,m.length)+"-"+d.substring(d.length-2,d.length);
    },
    go_order:function(k){
        //alert(k)
        //alert(r)
        _lSSaveOrUpdate( 'reserveId', k );//保存订单号 下个页面取出来使用
       // _lSSaveOrUpdate( 'hotelId', r );//保存酒店id 下个页面取出来使用
	    window.location.href=indexUrl+'/app/payment.html?_t=' + Math.random();//点击支付跳到支付页面

},
     go_current:function(id){//当前订单
         _lSSaveOrUpdate( 'reserveId', id );
         window.location.href=indexUrl+'/app/order-current.html?_t=' + Math.random();
     },
     cancel:function(id){
         var that=this;
         var params = {};
         params.id =id;
         params.token = that.token;
         sendRequest('/weChartOrder/cancelReserve', params, function(res) {
             goLogin(res)
             //res = res.data;
             console.log('okla');
             console.log(res);
            // that.go_login_home(res);
             if(res.status == '1') {
                 tips(res.returnMsg);
                 //that.get_data();
                 window.location.reload();//重新加载页面
                 //that.hisOrder=res.rows;

                 //var array = [];
             }
         });
     },
 get_data:function(){
        var that=this;
        var params = {};
        params.page=this.page;
        params.pageSize =7;
        params.reserveStatus=that.order_type;
        // params.customId = 1;
        params.customId = this.userId;
        params.token = this.token;
        //params.rows = 5;
        //params.provinceId = provinceId;
        //params.cityId = cityId;
    sendRequest('/weChartOrder/listInfo', params, function(res) {
        _lSSaveOrUpdate( 'forwordPage','/app/history-order.html');
        goLogin(res)
        //res = res.data;
        console.log('okla');
        console.log(res);
        goLogin(res);
        if(res.status == '1') {
            //that.hisOrder=res.rows;
            console.log(that.hisOrder);
            if(res.rows!=null){
	            for(var i=0;i<res.rows.length;i++){//由于是时间戳所以要重新拼接数组
	    	        var cart = {};
		            cart.reserveNo = res.rows[i].reserveNo;//订单号
		            cart.roomsNum = res.rows[i].roomCount;//房间数
		            //cart.inTime = res.rows[i].inTime;//进店时间
		            cart.inTime = that.fmtDate(res.rows[i].inTime);//进店时间
		            cart.outTime = that.fmtDate(res.rows[i].outTime);//离店时间
		            cart.hotelName = res.rows[i].hotelName;//入住分店
		            cart.totalPrice = res.rows[i].unpaidMoney;//总价
		            cart.reserveStatus = res.rows[i].reserveStatus;//订单状态
                    cart.dayCount = res.rows[i].dayCount;//入住的总天数
		            cart.hotel = res.rows[i].hotel;//订单的酒店id
		            cart.id = res.rows[i].id;//订单的酒店id
		            that.hisOrder.push(cart);
	  		        //that.city_aggre.push(res.rows[i].provinceId);
			        //that.city_aggre.push(res.rows[i].provinceId);
	  		        //console.log(that.hisOrder);
			   }
			 console.log(that.hisOrder);

    	} if(res.rows==''||res.rows==null){
    		that.tipMsg='加载完毕啦!';
    	}
    //var array = [];
       }
    });

  },
  go_login_home:function(res){//统一验证状态
        console.log('+++++++')
        console.log(res);
        if(res.returnCode=="MEM-1001"){
            //alert('这里跳转到登录页')
            window.location.href=backUrl;
         }
    },

  },
  computed: {

 },
 watch:{
 	order_type:function(){
 	 this.hisOrder.length=0;//清空原来的数据集合，使之重新渲染
 	 this.page=1;
 	 //alert(this.order_type);
 	 this.get_data();
 	} 
 },

 components:{
        
  }
 
      
});